#include "../xc.h"
#include "../GenericTypeDefs.h"
#include "../src/Uart4.h"
#include "../src/PanelComm.h"
#include "string.h"
#include "stdio.h"
#include "Debug.h"

IOCOMM IoComm;

uint8_t IoRxHead = 0;
uint8_t IoRxTail = 0;
uint8_t IoTxHead = 0;
uint8_t IoTxTail = 0;
uint8_t IoTxData[IO_BUF_LEN];
uint8_t IoRxData[IO_BUF_LEN];

void IoComm_RxTx(void);

void IoComm_RxTx(void)
{
    while(RX_FULL)    
    {  
        IoRxData[IoRxTail] = U4RXREG;         
        IoRxTail = (IoRxTail + 1) & (IO_BUF_LEN - 1);      
    }

    while(!TX_FULL)
    {
        if(IoTxHead != IoTxTail)           
        {             
            U4TXREG = IoTxData[IoTxHead];
            IoTxHead = (IoTxHead + 1) & (IO_BUF_LEN - 1); 
        }  
        else
        {        
            break;
        }
    }  
}